package cpr.data;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import data.ClusterDescriptor;
import data.IClusterDescriptor;
import data.IWorksetItem;

public class WorksetItem implements IWorksetItem, Comparable {
	int id;
	private List childs;
	private WorksetItem parent;
	private IClusterDescriptor cluster;
	
	private int rootNumberOfChilds;
	
	public WorksetItem() {
		childs = new ArrayList();
	}
	
	public WorksetItem(SplitCluster sc) {
		this();
		setClusterDescriptor(new ClusterDescriptor(sc.aRule, sc.aVector, sc._counter));
	}
	
//	public void setId(int i) {
//		id = i;
//	}
//	public int getId() {
//		return id;
//	}
	public List getChlids() {
		return childs;
	}
	public IClusterDescriptor getClusterDescriptor() {
		return cluster;
	}
	public WorksetItem getParent() {
		return parent;
	}
	public void setClusterDescriptor(IClusterDescriptor cl) {
		cluster = cl;
	}
	public void setParent(WorksetItem par) {
		parent = par;
	}
	public int getClusterSize() {
		return getClusterDescriptor().getSize();
	}
	public int getChildSize() {
		int s = 0;
		for (Iterator iter = childs.iterator(); iter.hasNext();) {
			IWorksetItem ch = (IWorksetItem) iter.next();
			s = s+ ch.getClusterSize();
		}
		return s;
	}

    
    public int compareTo(Object arg0) {
        WorksetItem that = (WorksetItem)arg0;
        return ClusterDescriptor.compare(this.cluster, that.cluster);
    }

    @Override
    public boolean equals(Object arg0) {
        WorksetItem that = (WorksetItem)arg0;
        // TODO Auto-generated method stub
        return cluster.equals(that.cluster);
    }

    @Override
    public int hashCode() {
        return cluster.hashCode();
    }

    @Override
    public String toString() {
        StringBuffer sb = new StringBuffer();
        sb.append(getClusterDescriptor().toString());
        // TODO Auto-generated method stub
        return sb.toString();
    }

	public int getRootNumberOfChilds() {
		return rootNumberOfChilds;
	}

	public void setRootNumberOfChilds(int rootNumberOfChilds) {
		this.rootNumberOfChilds = rootNumberOfChilds;
	}

    
    
    
    
    
}
